package adapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import bean.AnswerCardBean;
import student.andlei.com.student.R;
import ui.activity.LookSubmittedActivity;

public class AnswerCardAdapter extends BaseQuickAdapter<AnswerCardBean.mlist,BaseViewHolder>{
    private SheetShapeListAdapter questionListAdapter;
    private Activity context;
    private int student_task_id;
    private List<AnswerCardBean.mlist> data;
    private boolean isCommit;
    //批改状态 0未提交 10待批改 100已批改
    public AnswerCardAdapter(Activity context, int layoutResId, @Nullable List<AnswerCardBean.mlist> data,boolean isCommit,int student_task_id) {
        super(layoutResId, data);
        this.context = context;
        this.data = data;
        this.student_task_id = student_task_id;
        this.isCommit = isCommit;
    }

    @Override
    protected void convert(final BaseViewHolder helper, AnswerCardBean.mlist item) {
        helper.setText(R.id.tv_sheet_title,item.paper_type_name);
        questionListAdapter = new SheetShapeListAdapter(R.layout.item_answersheetcard,item.questions,isCommit);
        RecyclerView recyclerView = helper.getView(R.id.rcly_select);
        GridLayoutManager layoutManager = new GridLayoutManager(context,10) {
            @Override
            public RecyclerView.LayoutParams generateDefaultLayoutParams() {
                return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
            }
        };
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(questionListAdapter);
        questionListAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if(isCommit){
                    int order =  0;
                    helper.getAdapterPosition();
                    for (int i =0;i<helper.getAdapterPosition();i++){
                        Log.i("data--->",""+ data.get(i).questions.size());
                        data.get(i).questions.size();
                        order+=data.get(i).questions.size();
                    }
                    Intent intent = new Intent(context, LookSubmittedActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putInt("student_task_id",student_task_id);
                    bundle.putInt("order",(order+position));
                    intent.putExtra("bundle",bundle);
                    context.startActivity(intent);
//                    context.finish();
                }else {
                    Intent intent = new Intent();
                    int order =  0;
                    helper.getAdapterPosition();
                    for (int i =0;i<helper.getAdapterPosition();i++){
                        Log.i("data--->",""+ data.get(i).questions.size());
                        data.get(i).questions.size();
                        order+=data.get(i).questions.size();
                    }
                    intent.putExtra("order",(order+position));
                    context.setResult(0,intent);
                    context.finish();
                }

//                Intent intent = new Intent(context,);
//                intent.putExtra("");
//                context.startActivity();
            }
        });
    }
}
